import {HtmlNode, HtmlNodeModel} from '@logicflow/core'
//自定义条件节点
// 提供节点
class CustomIfNode extends HtmlNode {
  constructor(props){
    props.model.text.y = props.model.y + 20
    super(props)
  }
    
  setHtml(rootEl) {
    const { properties } = this.props.model;
    const el = document.createElement("div");
    el.className = "uml-wrapper";
    el.innerHTML = `
    <img width="58" src='${properties.status === 'COMPLETED' ? require('./img/if1.png') : (properties.status === 'FAILED' ? require('./img/if0.png') : require('./img/if.png'))}' alt=""/>
    `;
    rootEl.innerHTML = "";
    rootEl.appendChild(el);
  }
}
 
// 提供节点的属性
class CustomIfModel extends HtmlNodeModel {
  setAttributes() {
    const width = 58;
    const height = 80;
    this.width = width;
    this.height = height;
    this.anchorsOffset = [
      [width / 2, -15],
      [0, height / 2 - 30],
      [-width / 2, -15],
      [0, -height / 2],
    ];
  }
}
 
export default {
  type: 'CustomIf',
  view: CustomIfNode,
  model: CustomIfModel
}